package com.web.service.impl;

import com.web.entity.Admin;
import com.web.mapper.AdminMapper;
import com.web.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class AdminImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    //新增管理员
    @Override
    public void save(Admin admin) {
        admin.setCreateTime(LocalDateTime.now());
        admin.setUpdateTime(LocalDateTime.now());
        adminMapper.insert(admin);
    }

    //删除管理员
    @Override
    public void delete(Integer id) {
        adminMapper.delete(id);
    }

    //根据id查询管理员信息
    @Override
    public Admin findById(Integer id) {
        return adminMapper.findById(id);
    }

    //修改管理员
    @Override
    public void update(Admin admin) {
        admin.setCreateTime(LocalDateTime.now());
        admin.setUpdateTime(LocalDateTime.now());
        adminMapper.update(admin);
    }


    //查询所有管理员信息
    @Override
    public List<Admin> findAll() {
        return adminMapper.selectAll();
    }
}
